﻿<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DraftSchedule.aspx.vb" Inherits="DraftSchedule" %>

<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <div class="main_container">
        <div class="header_contain">
            <div class="left_logo">
                <img alt="" src="resources/images/Top_Left.png" />
                <span>Welcome, [Name]&nbsp;&nbsp; | Logout</span>
            </div>
        </div>
        <div class="contain_body">
            <div class="Left_Menu">
                <table>
                    <tr>
                        <td class="menu_title">
                            MANAGE INFORMATION
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_item">
                            Lecturer Info
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_item">
                            Student Info
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_item">
                            Student Interview Sessions
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_title">
                            MANAGE SCHEDULE
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_item">
                            Draft Schedule
                        </td>
                    </tr>
                    <tr>
                        <td class="menu_item">
                            Final Schedule
                        </td>
                    </tr>
                </table>
                <div class="menu_bottom">
                </div>
            </div>
            <div class="details_contain">
                <form action="" id="submitForm" method="post">
                <input type="hidden" id="hiddenID" name="hiddenID" value="" />
                <input type="hidden" id="action" name="action" value="" />
                <input type="hidden" id="target" name="target" value="" />
                <div class="import">
                    <span class="title">MOCK INTERVIEW SCHEDULE</span>
                    <div class="tool">
                        <input type="button" value="Generate Schedule" onclick="" />
                        <input type="button" value="Export" onclick=";" />
                    </div>
                </div>
                <br />
                <div class="checkbox_group">
                    <span style="font-weight: bold; margin-left: 20px;">Select group to post schedule:</span>
                    <div class="checkboxes">
                        <%
                            Dim sEdit As String = ""
                            If Not IsNothing(Request.QueryString("edit")) Then
                                sEdit = Request.QueryString("edit")
                            End If
                            Dim dv2 As DataView = mDataStore.GetGroups().Tables(0).DefaultView
                            Dim Output As StringBuilder = New StringBuilder("")
                            If dv2.Count > 0 Then
                                For Each dr As DataRowView In dv2
                                    Output.AppendFormat("<span><input type='checkbox' value='{0}' name='{0}' id='{0}' />{0}</span>", dr("WPP_Number"))
                                Next
                            Else
                                Output.Append("<spand>no group found</span>")
                            End If
                            Response.Write(Output.ToString)
                        %>
                    </div>
                    <input style="margin: 0 0 10px 20px;" type="button" value="Post Schedule" name="post_schedule"
                        id="post_schedule" />
                </div>
                <div class="list">
                    <table class="Lecturer_List" style="border-collapse: collapse; margin: 10px 0 0 20px;
                        width: 804px;">
                        <%
                            Dim dt As DataTable = mDataStore.GetAllSession().Tables(0)
                            If dt.Rows.Count > 0 Then
                                Dim sGroupNo As String = ""
                                Dim sRoom As String = ""
                                Dim sEditButtons As String = ""
                                'sEditButtons += "<span class='input_icon' onclick=""confirm_me('" & sEdit & "','{0}');"">"
                                sEditButtons += "<img title='Confirm' alt='Confirm' src='resources/images/yes_icon.png'/></span>"
                                sEditButtons += "<span class='input_icon' onclick=""cancel_me();"">"
                                sEditButtons += "<img title='Cancel' alt='Cancel' src='resources/images/no_icon.png'/></span>"
                                For Each dr As DataRow In dt.Rows
                                
                                    sGroupNo = dr("Schd_WPPGrp").ToString.Split(" ")(1)
                                    sRoom = "Room_" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession")
                                
                               
                        %>
                        <tr>
                            <th>
                                Posted on
                            </th>
                            <th>
                                <%= dr("Schd_PostedOn")%>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                        </tr>
                        <tr>
                            <th>
                                Group:
                            </th>
                            <th>
                                <%= sGroupNo%>
                            </th>
                            <th>
                            </th>
                            <th>
                                Date & Time:
                            </th>
                            <th>
                                <%= CDate(dr("WPP_StartDateTime")).ToString("DD MMM yyyy")%>
                            </th>
                            <th>
                                From:
                                <%= CDate(dr("WPP_StartDateTime")).ToString("HH:mm")%>
                            </th>
                            <th>
                                To:
                                <%= CDate(dr("WPP_EndDateTime")).ToString("HH:mm")%>
                            </th>
                            <th>
                            </th>
                        </tr>
                        <tr>
                            <th>
                                Room:
                            </th>
                            <th>
                                <%  If sEdit = sRoom Then
                                        Response.Write("<input type='text' name='" & sRoom & "' id='" & sRoom & "' value='" & dr("Schd_Room") & "' />")
                                    Else
                                        Response.Write(dr("Schd_Room"))
                                    End If
                             
                                %>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                            </th>
                            <th>
                                <%  If sEdit <> sRoom Then
                                        Response.Write("<input type='button' value='Edit' name='Edit_Room' onclick=""editMe('" & sRoom & "','');"" />")
                                    Else
                                        Response.Write("<span class='input_icon' onclick=""confirm_me('" & sRoom & "','');"">")
                                        Response.Write(sEditButtons)
                                 
                                    End If
                                  
                                %>
                            </th>
                            <th>
                            </th>
                        </tr>
                        <%
                            Dim dtLecturerSession As DataTable = mDataStore.GetLecturerSession(dr("Schd_WPPGrp"), dr("Schd_InterviewSession")).Tables(0)
                            Dim sSessionID As String = ""
                            Dim sLtrName As String = ""
                            For iRun As Integer = 0 To 2
                                If dtLecturerSession.Rows.Count - 1 >= iRun Then
                                    sSessionID = dtLecturerSession.Rows.Item(iRun)("ID")
                                    sLtrName = dtLecturerSession.Rows.Item(iRun)("Ltr_Name")
                                Else
                                    sSessionID = "new" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession")
                                    sLtrName = ""
                                End If
                                    
                                If iRun = 0 Then
                                    Response.Write("<tr><th>Lecturers:</th>")
                                Else
                                    Response.Write("<tr><th></th>")
                                End If
                                'write name or input
                                If sEdit = "Lecturer_" & sSessionID Then
                                    'write list of available lecturer 
                                    Response.Write("<th>")
                                    Response.Write(mDataStore.GetAvailableLecturer(sLtrName, sSessionID))
                                    Response.Write("</th>")
                                Else
                                    Response.Write("<th>" & sLtrName & "</th>")
                                End If
                                    
                                Response.Write("<th></th><th></th><th></th><th></th><th>")
                                    
                                'write 1 button or 2 buttons
                                If sEdit = "Lecturer_" & sSessionID Then
                                    Response.Write("<span class='input_icon' onclick=""confirm_me('Lecturer_" & sSessionID & "','');"">")
                                    Response.Write(sEditButtons)
                                Else
                                    Response.Write("<input type='button' value='Edit' name='EditLecturer' onclick=""editMe('Lecturer_" & sSessionID & "','');"" />")
                                End If
                                Response.Write("</th><th>")
                                Response.Write("<input type='button' value='Remove' name='RemoveLecturer' onclick=""RemoveMe('" & sSessionID & "','lecturer','" & sLtrName & "');"" /></th></tr>")
                            Next
                            
                        %>
                        <tr class="schedule_title">
                            <th>
                                From
                            </th>
                            <th>
                                To
                            </th>
                            <th>
                                Student ID
                            </th>
                            <th>
                                Student Name
                            </th>
                            <th>
                                Occupation
                            </th>
                            <th>
                                Company
                            </th>
                            <th>
                                Edit
                            </th>
                            <th>
                                Remove
                            </th>
                        </tr>
                        <%
                            Dim dtStudent As DataTable = mDataStore.GetStudentSession(dr("Schd_WPPGrp"), dr("Schd_InterviewSession")).Tables(0)
                            If dtStudent.Rows.Count > 0 Then
                                Dim sWrite As StringBuilder = New StringBuilder("")
                                Dim dtRunTime As DateTime = New DateTime(Now.Year, Now.Month, Now.Day, CDate(dr("WPP_StartDateTime")).Hour, CDate(dr("WPP_StartDateTime")).Minute, 0)
                                Dim iCount As Integer = 1
                                Dim iStep As Integer = 0
                                While iStep <= dtStudent.Rows.Count - 1
                                    
                                    If dtStudent.Rows(iStep)("Std_SessionOrder") = iCount Then
                                        
                                        sWrite.Append("<tr>")
                                        sWrite.AppendFormat("<td>{0}</td>", dtRunTime.ToString("HH:mm"))
                                        dtRunTime = dtRunTime.AddMinutes(10)
                                        sWrite.AppendFormat("<td>{0}</td>", dtRunTime.ToString("HH:mm"))
                                        sWrite.AppendFormat("<td>{0}</td>", dtStudent.Rows(iStep)("Std_Number"))
                                        If sEdit = "Student_" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession") & "_" & iCount Then
                                            sWrite.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", mDataStore.GetAvailableStudent(dtStudent.Rows(iStep)("Std_Name")), dtStudent.Rows(iStep)("Std_Position"), dtStudent.Rows(iStep)("Std_Company")) 'format:Student_ChangeTime
                                            sWrite.Append("<td>")
                                            sWrite.AppendFormat("<span class='input_icon' onclick=""confirm_me('" & sEdit & "','');"">")
                                            sWrite.AppendFormat(sEditButtons)
                                            sWrite.Append("</td>")
                                            
                                        Else
                                            sWrite.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", dtStudent.Rows(iStep)("Std_Name"), dtStudent.Rows(iStep)("Std_Position"), dtStudent.Rows(iStep)("Std_Company"))
                                            sWrite.Append("<input type='button' value='Edit' name='EditStudent' onclick=""editMe('" & "Student_" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession") & "_" & iCount & "_" & dtStudent.Rows(iStep)("Std_Number") & "','');"" />")
                                        End If
                                        sWrite.Append("<td>")
                                        sWrite.Append("<input type='button' value='Remove' name='RemoveStudent' onclick=""RemoveMe('" & dtStudent.Rows(iStep)("Std_Number") & "','student','" & dtStudent.Rows(iStep)("Std_Name") & "');"" />")
                                        sWrite.Append("</td>")
                                        sWrite.Append("</tr>")
                                        iCount += 1
                                        iStep += 1
                                    Else
                                        sWrite.Append("<tr>")
                                        sWrite.AppendFormat("<td>{0}</td>", dtRunTime.ToString("HH:mm"))
                                        dtRunTime = dtRunTime.AddMinutes(10)
                                        sWrite.AppendFormat("<td>{0}</td>", dtRunTime.ToString("HH:mm"))
                                        sWrite.Append("<td></td>")
                                        If sEdit = "Student_" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession") & "_" & iCount & "_" Then
                                            sWrite.AppendFormat("<td>{0}</td><td></td><td></td>", mDataStore.GetAvailableStudent("")) 'format:Student_ChangeTime
                                            sWrite.Append("<td>")
                                            sWrite.AppendFormat("<span class='input_icon' onclick=""confirm_me('" & sEdit & "','');"">")
                                            sWrite.AppendFormat(sEditButtons)
                                            sWrite.Append("</td><td></td>")
                                        Else
                                            sWrite.Append("<td></td><td></td><td></td>")
                                            sWrite.Append("<input type='button' value='Edit' name='EditStudent' onclick=""editMe('" & "Student_" & dr("Schd_WPPGrp") & "_" & dr("Schd_InterviewSession") & "_" & iCount & "_','');"" />")
                                            sWrite.Append("<td></td>")
                                        End If
                                        sWrite.Append("</tr>")
                                        
                                        iCount += 1
                                    End If
                                End While
                            End If
                        Next
                    End If
                        %>
                    </table>
                </div>
                </form>
            </div>
            <br />
        </div>
        <br clear="all" />
        <div class="footer">
            <br />
            Developed by Incentives Team
        </div>
    </div>
</body>
</html>
